import cal from './cal';
import isPercentNumber from "./isPercentNumber";
const _a = [
    'width',
    'height',
    'left',
    'top',
    'fontSize',
    'lineHeight',
    'letterSpacing',
    'borderRadius',
    'borderWidth',
    'borderTop',
    'borderBottom',
    'borderLeft',
    'borderRight',
    'borderTopWidth',
    'borderBottomWidth',
    'borderLeftWidth',
    'borderRightWidth',
    'borderTopStyle',
    'borderBottomStyle',
    'borderLeftStyle',
    'borderRightStyle',
    'borderTopColor',
    'borderBottomColor',
    'borderLeftColor',
    'borderRightColor',
    'margin',
    'padding',
    'marginLeft',

];
/**
 * 计算shape的样式兼容性
 * @param shape 组件的shape对象
 * @param ratio 比例系数
 * @returns {Array|*}
 */
export default function resizeShape(shape, ratio) {
    if (!shape || !shape.toJS) return shape;
    shape = shape.set('boxSizing', 'border-box');
    if (shape.get('alignItems') || shape.get('justifyContent')) {
        shape = shape.update('display', display => (display || 'flex')).set('flexDirection', 'column');
    }
    shape = shape.sortBy((v, k) => _a.indexOf(k), (a, b) => (a > b ? 1 : -1)).map((v, k) => {
        if (k !== undefined && v !== undefined) {
            if (_a.indexOf(k) > -1) {
                if (!isPercentNumber(v)) { // 百分比的数字不做调整
                    v = cal(v, undefined, v => v && (v *= ratio));
                }
            }
        }
        return v;
    });
    return shape;
}
